package com.company.strs;

public class BalancedStringSplit {
    public int balancedStringSplit(String s) {

        int leftCount = 0;
        int rightCount=0;
        int count = 0;
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if (leftCount == rightCount) {
                count++;
                leftCount=0;
                rightCount=0;
            }
            if (c == 'L') {
                leftCount++;
            }
            if (c == 'R') {
                rightCount++;
            }
        }
        return count;
    }
}
